<?php
error_reporting(E_ERROR | E_PARSE);
//test_tokens script script created by Robert Cox on April 12th 2011
//Commandline Usage: ./test_tokens.php commandline (debug)
//URL Usage: http://.../../test_tokens.php?web=1              <= normal mode
//      -or- http://.../../test_tokens.php?web=1&debug=1      <= debug mode

// set start time
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;

if(isset($_GET['debug'])){
                $debug = TRUE;
                $GLOBALS["debug"] = TRUE;
        } else {
                unset($debug);
        }

if(isset($_GET['web'])){
                $web = TRUE;
                $GLOBALS["web"] = TRUE;
        } else {
                unset($web);
        }


if (isset($debug)) { 
	echo "<br>* * * * *  D E B U G = O N * * * * *<br>";
	if (isset($web)) { 
		echo "<br>* * * * *  W E B = O N  * * * * *<br>";}
}

$invalidate = "";

$status = "";
$testname = "Token Test";
$testdesc = "Verify that all the tokens are working";
$testurl = "test_tokens.php";
$testtime = time();
$testtime_upperlimit = $testtime+10;

// Setup the archival file name for the test
$datestamp = date("YmdGis",$testtime);
$tokendate = date("Y-m-d",$testtime);
$tokentime = date("G:i:s",$testtime);
$ValidDateTime = date("Y-m-d H:i:s$invalidate",$testtime); //2011-04-12 15:05:38
$ValidDate = date("mdy$invalidate",$testtime); //041211
$ValidTime = date("G:i:s$invalidate",$testtime); //15:05:38
$directory = "/http/matchtest/archived_results/tokentest/";

if(!is_dir($directory)){
	if(!mkdir($directory, 0777)) {
		die('Failed to create directory: '.$directory);
	}
}


$today = date("F j, Y, g:i a");
$random = rand();
$UserAgent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16";
$Targeting="\"house\"";

function TraceInfo($output,$string,$debug) {
        $line_match = array_values(preg_grep("/$string/", $output));
            if (isset($GLOBALS["debug"])) { echo "DEBUG - string:  ".$string."<br>";}
            if (isset($GLOBALS["debug"])) { echo "DEBUG - output:  <br><pre>"; print_r($output); echo "</pre><br>";}
            if (isset($GLOBALS["debug"])) { echo "DEBUG - line_match:<br><pre>"; print_r($line_match); echo "</pre><br>";}
			$explode = explode("| ", $line_match[0]);
			if($string == "FCID"){ $explode = explode("| ", $line_match[2]); };
			if($string == "DATE"){ $explode = explode("| ", $line_match[1]); };
			if($string == "TIME"){ $explode = explode("| ", $line_match[1]); };
			$result = trim(str_replace("<br>","",$explode[1]));
        if (isset($GLOBALS["debug"])) { echo "DEBUG - result:  ".$result."<br>";}
		return $result;
}

// setup command line args (commandline only)

if (isset($argv[1])) { $commandline = $argv[1]; unset($debug);} 

        $AdCallURL = "http://crtldev.aimatch.com:60000";
		$Directive = "/canary/hserver/";
        $PathInfo = "mid=".$testtime."/area=token/random=".$random."/generic=abcdef/date=".$tokendate."/time=".$tokentime."/canary=bird";
        $Query = "querystring";
        $client_headers[] = sprintf('X-Forwarded-For: %s', $ClientIP);
		$ValidClickURL = $AdCallURL."$invalidate/canary/adclick/FCID=5/mid=".$testtime."/area=token/random=".$random."/generic=abcdef/date=".$tokendate."/time=".$tokentime."/canary=bird?".$Query;
		$ValidPreClickURL = $ValidClickURL."&relocate=$invalidate";
		$ValidVeriCountURL = "$invalidate<img src=\"".$AdCallURL."/canary/count/FCID=5/mid=".$testtime."/area=token/random=".$random."/generic=abcdef/date=".$tokendate."/time=".$tokentime."/canary=bird?".$Query."\" width=\"1\" height=\"1\" border=\"0\" style=\"display:none\" />";
        $ValidBeaconURL = "$invalidate".$AdCallURL."/canary/count/FCID=5/mid=".$testtime."/area=token/random=".$random."/generic=abcdef/date=".$tokendate."/time=".$tokentime."/canary=bird?".$Query;
		$url = "$AdCallURL$Directive$PathInfo?$Query";

		$ValidMedia = "http://tests.aimatch.com/media".$invalidate;
		$ValidAltText = "Test Tokens Alt Text".$invalidate;
		$ValidAltImage = "http://tests.aimatch.com/altimage".$invalidate;
		$ValidFCID = "5".$invalidate;
		$ValidRandom = $random.$invalidate;
		$ValidQuery = "querystring".$invalidate;
		$ValidPath = "/".$PathInfo.$invalidate;
		$ValidWidth = "125".$invalidate;
		$ValidHeight = "125".$invalidate;
		$ValidFltUInfo = "Flight User Info".$invalidate;
		$ValidCrtUInfo = "Creative User Info".$invalidate;
		$ValidReferrer = "http://canary.aimatch.com/canary_referer.php".$invalidate;
		if (isset($commandline)) { $ValidUserAgent = $UserAgent.$invalidate; }
		if (isset($web)) { $ValidUserAgent = $_SERVER['HTTP_USER_AGENT'].$invalidate; }
		$ValidGeneric = "abcdef".$invalidate;
		$ValidFormatField1 = "Format Field One".$invalidate;
		$ValidFormatField2 = "Format Field Two".$invalidate;
		$ValidFormatField3 = $ValidGeneric.$invalidate;
		$ValidFormatField4 = "Format Field >> Format Field One << Four".$invalidate;
		$ValidFormatField5 = "Format Field >> Format Field >> Format Field One << Four << Five".$invalidate;
		$ValidCanary = "bird".$invalidate;
		$ValidNonExistent = "".$invalidate;
		$ValidGeo_Ip = "10.160.247.191".$invalidate;
		
        $delay = 2500;

        // initilize the curl call
        $ch = curl_init();
        // set useragent
        if (isset($commandline)) { curl_setopt($ch, CURLOPT_USERAGENT, $UserAgent); }
        if (isset($web)) {curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); }
        // Set curl to use $url for http call
        curl_setopt($ch, CURLOPT_URL, $url);
        // show client headers
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // have curl put X-Forwarded-For into headers
        curl_setopt($ch,CURLOPT_HTTPHEADER, $client_headers);
        // store results as the return of curl_exec
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // Follow redirects
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);		
        // if HTML error 400 over over, fail
        curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
		// set Referrer
		curl_setopt ($ch, CURLOPT_REFERER, "http://canary.aimatch.com/canary_referer.php");

        $output = curl_exec($ch);
        if (isset($debug)) { echo "<br><pre><hr>HTTP Response Output:<br><br>"; print_r($output); echo "</pre><br><hr>"; }

        $output_array = preg_split('/[\n]/', $output, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

		
        if (isset($debug)) { echo "<br><pre><hr>HTTP Response Output (array):<br><br>"; print_r($output_array); echo "</pre><br><hr>"; }

        //get curl info
        $info = curl_getinfo($ch);
        if (isset($debug)) { echo "<br><pre><hr>CURL Response Info:<br><br>"; print_r($info); echo "</pre><br><hr>"; }


        //close curl connection
        curl_close($ch);

        /** get HTTP return header (code AND text) **/

        $http_response = array_values(preg_grep("/^HTTP/", $output_array));
        $http_array = explode(" ",$http_response[0]);
        $http_return_code = trim($http_array[1]);
        $http_return_text = trim($http_array[2]);
        if (isset($debug)) { echo "<br>DEBUG - HTTP CODE/TEXT: $http_response[0]<br>"; }

        /* check code = 200 and text equal OK, anything else we have an error */

        if ($http_return_text != "OK" || $http_return_code != "200") {
            if (isset($debug)) { echo "***** ALERT - HTTP CODE/TEXT: ".trim($http_response[0])." *****<br>"; }
				echo "HTTP return code/text was not 200/OK". trim($http_response[0])."<br>";
                die;
        }
		
		// count the number of elements in the response array
		$num_elements = count($output_array);
        if (isset($debug)) { echo "The Number Of Elements in the OUTPUT Array are: ".$num_elements." <br>"; }
		
		// format the items in the array as a long concatenated string.
		$y=0;
		while($y <= $num_elements){
			$formatted_output = $formatted_output.$output_array[$y]."\n";
			$formatted_output_web = $formatted_output_web.$output_array[$y]."<br>";
			$y++;
		}
        if (isset($debug)) { echo "The Formatted contents of OUTPUT are: ".$formatted_output_web." *****<br>"; }

	$pass=0;
	$fail=0;
// Check %%CLICKURL%%        
        $TraceTargeting = TraceInfo($output_array,"CLICKURL");
        if(strcmp($TraceTargeting,$ValidClickURL)==0){
			$message1 = "***** SUCCESS - %%CLICKURL%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidClickURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$clickurl_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%CLICKURL%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidClickURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$clickurl_status = "fail";		
			$fail++;
		}

// Check %%PRECLICKURL%%        
        $TraceTargeting = TraceInfo($output_array,"PRECLICKURL");
        if(strcmp($TraceTargeting,$ValidPreClickURL)==0){
			$message1 = "***** SUCCESS - %%PRECLICKURL%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidPreClickURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$preclickurl_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%PRECLICKURL%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidPreClickURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$preclickurl_status = "fail";			
			$fail++;
		}

// Check %%MEDIA%%        
        $TraceTargeting = TraceInfo($output_array,"MEDIA");
        if(strcmp($TraceTargeting,$ValidMedia)==0){
			$message1 = "***** SUCCESS - %%MEDIA%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidMedia;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$media_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%MEDIA%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidMedia;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$media_status = "fail";			
			$fail++;
		}

// Check %%ALTTEXT%%        
        $TraceTargeting = TraceInfo($output_array,"ALTTEXT");
        if(strcmp($TraceTargeting,$ValidAltText)==0){
			$message1 = "***** SUCCESS - %%ALTTEXT%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidAltText;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$alttext_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%ALTTEXT%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidAltText;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$alttext_status = "fail";			
			$fail++;
		}

// Check %%ALTIMAGE%%        
        $TraceTargeting = TraceInfo($output_array,"ALTIMAGE");
        if(strcmp($TraceTargeting,$ValidAltImage)==0){
			$message1 = "***** SUCCESS - %%ALTIMAGE%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidAltImage;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$altimage_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%ALTIMAGE%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidAltImage;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$altimage_status = "fail";			
			$fail++;
		}

// Check %%FCID%%        
        $TraceTargeting = TraceInfo($output_array,"FCID");
        if(strcmp($TraceTargeting,$ValidFCID)==0){
			$message1 = "***** SUCCESS - %%FCID%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFCID;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$fcid_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%FCID%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFCID;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$fcid_status = "fail";			
			$fail++;
		}

// Check %%RANDOM%%        
        $TraceTargeting = TraceInfo($output_array,"RANDOM");
        if(strcmp($TraceTargeting,$ValidRandom)==0){
			$message1 = "***** SUCCESS - %%RANDOM%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidRandom;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$random_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%RANDOM%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidRandom;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$random_status = "fail";			
			$fail++;
		}

// Check %%DATETIME%%        
        $TraceTargeting = TraceInfo($output_array,"DATETIME");
		$converted_datetime = strtotime($TraceTargeting);
        if (isset($debug)) { echo "TraceTargeting: ".$TraceTargeting."<br>"; }
        if (isset($debug)) { echo "converted_datetime".$converted_datetime."<br>"; }
        if (isset($debug)) { echo "testtime_upperlimit".$testtime_upperlimit."<br>"; }
		if($converted_datetime < $testtime_upperlimit){
			$message1 = "***** SUCCESS - %%DATETIME%% is valid and in range";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidDateTime;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$datetime_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%DATETIME%% is not valid or is out of range (+10 seconds)";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidDateTime;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$datetime_status = "fail";			
			$fail++;
		}

// Check %%DATE%%        
        $TraceTargeting = TraceInfo($output_array,"DATE");
        if(strcmp($TraceTargeting,$ValidDate)==0){
			$message1 = "***** SUCCESS - %%DATE%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidDate;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$date_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%DATE%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidDate;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$date_status = "fail";			
			$fail++;
		}

// Check %%TIME%%        
        $TraceTargeting = TraceInfo($output_array,"TIME");
        if(strcmp($TraceTargeting,$ValidTime)==0){
			$message1 = "***** SUCCESS - %%TIME%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidTime;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$time_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%TIME%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidTime;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$time_status = "fail";			
			$fail++;
		}

// Check %%QUERY%%        
        $TraceTargeting = TraceInfo($output_array,"QUERY");
        if(strcmp($TraceTargeting,$ValidQuery)==0){
			$message1 = "***** SUCCESS - %%QUERY%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidQuery;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$query_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%QUERY%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidQuery;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$query_status = "fail";			
			$fail++;
		}

// Check %%PATH%%        
        $TraceTargeting = TraceInfo($output_array,"PATH");
        if(strcmp($TraceTargeting,$ValidPath)==0){
			$message1 = "***** SUCCESS - %%PATH%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidPath;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$path_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%PATH%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidPath;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$path_status = "fail";			
			$fail++;
		}

// Check %%WIDTH%%        
        $TraceTargeting = TraceInfo($output_array,"WIDTH");
        if(strcmp($TraceTargeting,$ValidWidth)==0){
			$message1 = "***** SUCCESS - %%WIDTH%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidWidth;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$width_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%WIDTH%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidWidth;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$width_status = "fail";			
			$fail++;
		}

// Check %%HEIGHT%%        
        $TraceTargeting = TraceInfo($output_array,"HEIGHT");
        if(strcmp($TraceTargeting,$ValidHeight)==0){
			$message1 = "***** SUCCESS - %%HEIGHT%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidHeight;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$height_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%HEIGHT%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidHeight;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$height_status = "fail";			
			$fail++;
		}

// Check %%FLTUINFO%%        
        $TraceTargeting = TraceInfo($output_array,"FLTUINFO");
        if(strcmp($TraceTargeting,$ValidFltUInfo)==0){
			$message1 = "***** SUCCESS - %%FLTUINFO%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFltUInfo;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$fltuinfo_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%FLTUINFO%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFltUInfo;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$fltuinfo_status = "fail";			
			$fail++;
		}

// Check %%CRTUINFO%%        
        $TraceTargeting = TraceInfo($output_array,"CRTUINFO");
        if(strcmp($TraceTargeting,$ValidCrtUInfo)==0){
			$message1 = "***** SUCCESS - %%CRTUINFO%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidCrtUInfo;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$crtuinfo_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%CRTUINFO%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidCrtUInfo;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$crtuinfo_status = "fail";			
			$fail++;
		}

// Check %%REFERER%%        
        $TraceTargeting = TraceInfo($output_array,"REFERER");
        if(strcmp($TraceTargeting,$ValidReferrer)==0){
			$message1 = "***** SUCCESS - %%REFERER%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidReferrer;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$referrer_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%REFERER%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidReferrer;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$referrer_status = "fail";			
			$fail++;
		}

// Check %%USERAGENT%%        
        $TraceTargeting = TraceInfo($output_array,"USERAGENT");
        if(strcmp($TraceTargeting,$ValidUserAgent)==0){
			$message1 = "***** SUCCESS - %%USERAGENT%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidUserAgent;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$useragent_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%USERAGENT%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidUserAgent;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$useragent_status = "fail";			
			$fail++;
		}

// Check %%GENERIC%%        
        $TraceTargeting = TraceInfo($output_array,"GENERIC");
        if(strcmp($TraceTargeting,$ValidGeneric)==0){
			$message1 = "***** SUCCESS - %%GENERIC%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidGeneric;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$generic_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%GENERIC%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidGeneric;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$generic_status = "fail";			
			$fail++;
		}

// Check %%FORMATFIELD1%%        
        $TraceTargeting = TraceInfo($output_array,"FORMATFIELD1");
        if(strcmp($TraceTargeting,$ValidFormatField1)==0){
			$message1 = "***** SUCCESS - %%FORMATFIELD1%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField1;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield1_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%FORMATFIELD1%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField1;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield1_status = "fail";			
			$fail++;
		}

// Check %%FORMATFIELD2%%        
        $TraceTargeting = TraceInfo($output_array,"FORMATFIELD2");
        if(strcmp($TraceTargeting,$ValidFormatField2)==0){
			$message1 = "***** SUCCESS - %%FORMATFIELD2%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField2;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield2_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%FORMATFIELD2%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField2;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield2_status = "fail";			
			$fail++;
		}

// Check %%VERICOUNTURL%%        
        $TraceTargeting = TraceInfo($output_array,"VERICOUNTURL");
        if(strcmp($TraceTargeting,$ValidVeriCountURL)==0){
			$message1 = "***** SUCCESS - %%VERICOUNTURL%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidVeriCountURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<xmp>".$message2."</xmp>";}
			if (isset($web)) { echo "<xmp>".$message3."</xmp><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$vericounturl_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%VERICOUNTURL%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidVeriCountURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<xmp>".$message2."</xmp>";}
			if (isset($web)) { echo "<xmp>".$message3."</xmp><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$vericounturl_status = "fail";			
			$fail++;
		}

// Check %%BEACONURL%%        
        $TraceTargeting = TraceInfo($output_array,"BEACONURL");
        if(strcmp($TraceTargeting,$ValidBeaconURL)==0){
			$message1 = "***** SUCCESS - %%BEACONURL%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidBeaconURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<xmp>".$message2."</xmp>";}
			if (isset($web)) { echo "<xmp>".$message3."</xmp><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$beaconurl_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%BEACONURL%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidBeaconURL;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<xmp>".$message2."</xmp>";}
			if (isset($web)) { echo "<xmp>".$message3."</xmp><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$beaconurl_status = "fail";			
			$fail++;
		}

// Check %%CANARY%%        
        $TraceTargeting = TraceInfo($output_array,"CANARY");
        if(strcmp($TraceTargeting,$ValidCanary)==0){
			$message1 = "***** SUCCESS - %%CANARY%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidCanary;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$canary_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%CANARY%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidCanary;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$canary_status = "fail";			
			$fail++;
		}

// Check %%GEO_IP%%        
        $TraceTargeting = TraceInfo($output_array,"GEO_IP");
        if(strcmp($TraceTargeting,$ValidGeo_Ip)==0){
			$message1 = "***** SUCCESS - %%GEO_IP%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidGeo_Ip;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$canary_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%GEO_IP%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidGeo_Ip;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$canary_status = "fail";			
			$fail++;
		}

// Check %%NONEXISTENT%%        
        $TraceTargeting = TraceInfo($output_array,"NONEXISTENT");
        if(strcmp($TraceTargeting,$ValidNonExistent)==0){
			$message1 = "***** SUCCESS - %%NONEXISTENT%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidNonExistent;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$canary_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%NONEXISTENT%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidNonExistent;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$canary_status = "fail";			
			$fail++;
		}

// Check %%FORMATFIELD3%%        
        $TraceTargeting = TraceInfo($output_array,"FORMATFIELD3");
        if(strcmp($TraceTargeting,$ValidFormatField3)==0){
			$message1 = "***** SUCCESS - %%FORMATFIELD3%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField3;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield3_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%FORMATFIELD3%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField3;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield3_status = "fail";			
			$fail++;
		}

// Check %%FORMATFIELD4%%        
        $TraceTargeting = TraceInfo($output_array,"FORMATFIELD4");
        if(strcmp($TraceTargeting,$ValidFormatField4)==0){
			$message1 = "***** SUCCESS - %%FORMATFIELD4%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField4;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield4_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%FORMATFIELD4%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField4;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield4_status = "fail";			
			$fail++;
		}

// Check %%FORMATFIELD5%%        
        $TraceTargeting = TraceInfo($output_array,"FORMATFIELD5");
        if(strcmp($TraceTargeting,$ValidFormatField5)==0){
			$message1 = "***** SUCCESS - %%FORMATFIELD5%% is valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField5;
			if (isset($web)) { echo "<font size=\"3\" color=\"green\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield5_status = "pass";
			$pass++;
        }
        else {
			$message1 = "***** ALERT - %%FORMATFIELD5%% is not valid";
			$message2 = "     Server Response: ".$TraceTargeting;
			$message3 = "      Valid Response: ".$ValidFormatField5;
			if (isset($web)) { echo "<font size=\"3\" color=\"red\"><b>".$message1."</b></font><br>";}
			if (isset($web)) { echo "<pre>".$message2."<br>";}
			if (isset($web)) { echo $message3."<br></pre><br>";}
			$ArchiveOutput = $ArchiveOutput.$message1."\n".$message2."\n".$message3."\n\n";
			$formatfield5_status = "fail";			
			$fail++;
		}

// Determine if the test was successful
	if (isset($web)) { echo "Summary of Results (29 total tests)<br>"; }
	if (isset($web)) { echo "Pass: ".$pass."<br>"; }
	if (isset($web)) { echo "Fail: ".$fail."<br>"; }
	
	$ArchiveOutput = "Summary of Results: \n    Pass: ".$pass."\n    Fail: ".$fail."\n\nDetailed Results:\n\n".$ArchiveOutput;
	if (isset($commandline)) { echo "\n\n------------------\n\nWritten to File:\n ".$ArchiveOutput."\n\n"; }
	
// Set the status of the test
	if($pass == 29) { $status = "pass"; }
	else { $status = "fail"; }
	
// Write out the information to the testresults.txt file.

$lines = file('/http/matchtest/testresults.txt');
$numitems = count($lines);

// Loop through our array, show HTML source as HTML source; and line numbers too.

if (isset($debug)) { echo "<br><pre><hr>HTTP Response Output:<br><br>"; print_r($lines); echo "</pre><br><hr>"; }

$newfile = $lines[0];
$i=1;
while($i <= $numitems) {
	$pieces = explode("|",$lines[$i]);
	if($testname == $pieces[1]){
		$replaced_line = $status."|".$testname."|".$testdesc."|".$testurl."|".$testtime."\n";
		$newfile = $newfile.$replaced_line;
	}
	else{
		$newfile = $newfile.$lines[$i];
	}
	$i++;
}

if (isset($debug)) { echo "<br><pre><hr>New File Output:<br><br>"; print_r($newfile); echo "</pre><br><hr>"; }

$fp = fopen('/http/matchtest/testresults.txt', 'w');

fwrite($fp, $newfile);
fclose($fp);

// Write out results of the test to a file 
if (isset($web)) { $testfilename = $directory."tokentest.web.".$status.".".$datestamp.".".$testtime.".txt"; }
if (isset($commandline)) { $testfilename = $directory."tokentest.commandline.".$status.".".$datestamp.".".$testtime.".txt"; }

if (!$fp1 = fopen($testfilename,'w')) {
    echo "Cannot open file ($testfilename)";
    exit;
}

fwrite ($fp1,$ArchiveOutput."\n\n");
fclose($fp1);


if (isset($debug)) { phpinfo(); }
?>

